﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using WBGModel;
using WBGBusiness;
using RecursosHumanos;

namespace Clinica
{
    public partial class frmConsulta3C : Form
    {
        public frmConsulta3C()
        {
            InitializeComponent();
        }

        private void frmFilme_Load(object sender, EventArgs e)
        {
            AtualizaGrid();
        }

        private void AtualizaGrid()
        {
            Cursor.Current = Cursors.WaitCursor;

            grd.DataSource = new BusConsulta().Listar();

            if (grd.Rows.Count > 0)
            {
                tsbEditar.Enabled = true;
                tsbDeletar.Enabled = true;
            }
            else
            {
                tsbEditar.Enabled = false;
                tsbDeletar.Enabled = false;
            }

            FormataGrid();

            Cursor.Current = Cursors.Default;
        }

        private void FormataGrid()
        {
            grd.Columns["idConsulta"].HeaderText = "ID";
            grd.Columns["Paciente"].HeaderText = "Paciente";
            grd.Columns["inicioPrevisto"].HeaderText = "Início Previsto";
            grd.Columns["inicio"].HeaderText = "Início Efetivo";

            grd.Columns["idConsulta"].Width = 73;
            grd.Columns["Paciente"].Width = 260;
            grd.Columns["inicioPrevisto"].Width = 110;
            grd.Columns["inicio"].Width = 110;

            grd.Columns["fimPrevisto"].Visible = false;
            grd.Columns["fim"].Visible = false;
            grd.Columns["idPaciente"].Visible = false;
            grd.Columns["observacao"].Visible = false;
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void grd_Click(object sender, EventArgs e)
        {
            try
            {
                //grd.CurrentRow.Cells[0].ToolTipText = FilmeGenero.Find(Convert.ToInt32(grd.CurrentRow.Cells["genero"].Value.ToString()));
            }
            catch { }
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            frmConsulta3C_ frm = null;
            try
            {
                frm = new frmConsulta3C_(Request.Inserir, 0);
                frm.ShowDialog();
                AtualizaGrid();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.InnerException.Message, "Erro ao inserir", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (frm != null)
                    frm.Dispose();
            }
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            try
            {
                int id = Convert.ToInt32(grd.CurrentRow.Cells["idConsulta"].Value);
                var frm = new frmConsulta3C_(Request.Alterar, id);
                frm.ShowDialog();
                AtualizaGrid();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.InnerException.Message, "Erro ao alterar", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Deseja realmente excluir?", "Confirmação", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No)
                    return;

                int id = Convert.ToInt32(grd.CurrentRow.Cells["idConsulta"].Value);
                new BusConsulta().Deletar(id);
                AtualizaGrid();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.InnerException.Message, "Erro ao excluir", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
